/**Class Matrix For basic manipulation on matrix 
*
*
* 
* @Author : Vishwajeet Dusane 
*/

#include<stdio.h>
#include<math.h>
#include<iostream.h>
#include<fstream.h>
class Matrix
{
   public:
  double matrixA[100][100],matrixB[100],matrixX[100],matrixY[100];
  
  int row,column;
  
  
  int getMatrixA(char [50],char [50]);
  
  int  isTransformed();  //returns TRUE if the augmented matrix is Transformed matrix
  
  void getMatrixB();
  
  void printMatrix();
  
  double getElement(int,int);
  
  void setUpperTriangular();  //  make entries 0 where i>j 
  
  void setLowerTriangular();  //  make entries 0 where i<j
  
  int  isUpperTriangular(); 
  
  int  isLowerTriangular(); //return true 1 if matrix is lower triangular 
  
  
  void setRowNumber(int);   //set number of row for matrix 
  
  void setColumnNumber(int); //set number of column for matrix 
  
  double operator^(double); //return's 
  
  //int readMatrix(char [50]);
  };
  
  
  
  


double Matrix::operator^(double val)
{
      if(val==0)
      return 0;
      
      if(val<0)
       return (-1*val);
      else
       return val; 

}


void Matrix::setColumnNumber(int columnNumber)
{
  
     column=columnNumber;
  
}

void Matrix::setRowNumber(int rowNumber)
{
     row=rowNumber;

}


int Matrix::isUpperTriangular()
{

   for(int i=0;i<row;i++)
   {
     for(int j=0;j<(i-1);j++)
      
       if(matrixA[i][j]!=0)
        return 0;
   }
   return 1;
}


int Matrix::isLowerTriangular()
{
   
   for(int i=0;i<row;i++)
   {
     for(int j=i+1;j<column;j++)
       if(matrixA[i][j]!=0)
        return 0;
 
   }
    	
 return 1;
 
}

void Matrix::setLowerTriangular()
{
  
   for(int i=0;i<row;i++)
   {
     for(int j=i+1;j<column;j++)
     
       matrixA[i][j]=0;
 
   }
    

  
}
/** return true 1 if matrix is upper triangular matrix
 * 
 *
 */
void Matrix::setUpperTriangular()
{
   for(int i=0;i<row;i++)
   {
     for(int j=0;j<(i-1);j++)
     
      matrixA[i][j]=0;
   
   }


}
 int Matrix :: isTransformed()
{
    
  for(int i=0;i<row;i++)    //critical loop
  {
    for(int j=0;j<(i-1);j++)
    {
      if(matrixA[i][j]!=0)
      {
      cout<<"In isTransformed :"<<matrixA[i][j];
      return 0;
      }
    }
  
  }
  
  for(int i=0;i<row;i++)    //critical loop
  {
      if(matrixA[i][i]!=1)
      {
      cout<<"In isTransformed For Diagonal :"<<matrixA[i][i];
      return 0;
      }
     
  }
  
  return 1;
}

int Matrix:: getMatrixA(char fnameA[50],char fnameB[50])
 {
  
      ifstream fin(fnameB);
     
     if(!fin)
     {
       cout<<"ERROR : While Opening File "<<fnameB<<endl;
       return 0;
     }
     
     fin>>row;
     fin>>column;
     for(int i=0; i<row ;i++)
     {
        fin>>matrixB[i];
     }
    fin.close();
    printMatrix();
    
    
        ifstream  fin1(fnameA);
     
     if(!fin1)
     {
       cout<<"ERROR : While Opening File "<<fnameA<<endl;
       return 0;
     
     }
     
     fin1>>row;
     fin1>>column;
     for(int i=0; i<row ;i++)
     {
       for(int j=0;j<column;j++)
        {
            fin1>>matrixA[i][j];
	} 
     }
    fin1.close();
    printMatrix();

    
 } 
 
 
 void Matrix::getMatrixB()
 {
   
 matrixB[0]=32; 
 matrixB[1]=23;
 matrixB[2]=33;
 matrixB[3]=31; 
 
 } 
 
double Matrix::getElement(int row,int column)
{
   return matrixA[row][column];

}

void Matrix::printMatrix()
{
   for(int i=0 ;i<row;i++)
   {
    for(int j=0;j<column;j++)
     cout<<"  "<<matrixA[i][j];
     cout<<"| "<<matrixB[i]<<endl;
     
   }
}
